import * as actionTypes from '../action_types';
import { reqWeather } from '../../api'
// 登录
export const createSaveUserInfoAction = (value) =>{
    localStorage.setItem('user',JSON.stringify(value.user))
    localStorage.setItem('token',value.token)
    localStorage.setItem('isLogin',true)
    return{
        type: actionTypes.SAVE_USER_INFO,
        data:value
    }
}

// 退出登录
export const createDeleteUserInfoAction = () =>{
    localStorage.removeItem('user')
    localStorage.removeItem('token')
    localStorage.removeItem('isLogin')
    return{
        type: actionTypes.DELETE_USER_INFO,
    }
}
// 切换全屏
export const createScreenFullAction = () =>{
    return{
        type: actionTypes.CHANGE_FULL_SCREEN,
    }
}

// 获取当前天气信息
const weatherListAction = (weatherObj) =>{
    return{
        type:actionTypes.CHANGE_WEATHER,
        weatherObj
    }
}
export const createWeatherAction =  (city) =>{
    return ((dispatch)=>{
        reqWeather(city).then((res)=>{
            const action = weatherListAction(res);
            dispatch(action);
        })
    })

}